﻿using System;
using System.Collections.Generic;

using SharedGenomics.Core;
using SharedGenomics.Domain;
using SharedGenomics.DataTransfer;
using SharedGenomics.Workbench.Core;

namespace SharedGenomics.Workbench.Services
{
    public class WCFDataService : WCFClientHost, IDataService
    {
        public Maybe<string[]> GetUnavailbleMarkers(string[] markerNames)
        {
            return this.ExecuteProxyContract<DataService.IDataService, string[]>(ds => ds.GetUnavailableMarkers(markerNames)).Just();
        }

        public Maybe<Map> AddGroupMarkerByRsNumber(string markerName, long rsNumber)
        {
            return this.ExecuteProxyContract<DataService.IDataService, Map>(ds => ds.AddGroupMarkerByRsNumber(markerName, rsNumber)).Just();
        }

        public void AddGroupMarkerBySnpDetails(string markerName, short chromosome, long position)
        {
            this.ExecuteProxyContract<DataService.IDataService>(ds => ds.AddGroupMarkerBySnpDetails(markerName, chromosome, position));
        }

        public Maybe<EntityInfo[]> GetUserFileSchemaInfos()
        {
            return this.ExecuteProxyContract<DataService.IDataService, EntityInfo[]>(ds => ds.GetUserFileSchemaInfos()).Just();
        }

        public Maybe<FileSchema> GetSchema(int fileSchemaId)
        {
            return this.ExecuteProxyContract<DataService.IDataService, FileSchema>(ds => ds.GetSchema(fileSchemaId)).Just();
        }

        public void AddSchema(FileSchema schema)
        {
            this.ExecuteProxyContract<DataService.IDataService>(ds => ds.AddSchema(schema));
        }

        public Maybe<EntityInfo[]> GetUserFileSetInfos()
        {
            return this.ExecuteProxyContract<DataService.IDataService, EntityInfo[]>(ds => ds.GetUserFileSetInfos()).Just();
        }

        public Maybe<FileSetUploadInfo> CreateFileSet(string fileSetName, int fileSchemaId, SharedGenomics.DataAccess.GenotypeDataFileFormat genotypeFileFormat)
        {
            return this.ExecuteProxyContract<DataService.IDataService, FileSetUploadInfo>(ds => ds.CreateFileSet(fileSetName, fileSchemaId, genotypeFileFormat)).Just();
        }

        public void CreateDataSet(DataSetInfo dataSetInfo)
        {
            this.ExecuteProxyContract<DataService.IDataService>(ds => ds.CreateDataSet(dataSetInfo));
        }

        public Maybe<EntityInfo[]> GetUserDataSetInfos()
        {
            return this.ExecuteProxyContract<DataService.IDataService, EntityInfo[]>(ds => ds.GetUserDataSetInfos()).Just();
        }

        public Maybe<DataSetSummary[]> GetUserDataSetSummaries()
        {
            return this.ExecuteProxyContract<DataService.IDataService, DataSetSummary[]>(ds => ds.GetUserDataSetSummaries()).Just();
        }

        public Maybe<JobDetails[]> GetUserJobs(JobSpecification specification, int[] idsToIgnore)
        {
            return this.ExecuteProxyContract<DataService.IDataService, JobDetails[]>(ds => ds.GetUserJobs(specification, idsToIgnore)).Just();
        }

        public Maybe<bool> IsUserRegisteredForSharedGenomics()
        {
            return this.ExecuteProxyContract<DataService.IDataService, bool>(ds => ds.IsUserRegisteredForSharedGenomics()).Just();
        }

        public Maybe<JobResultsFileLocationInfo> GetJobResultsFileLocation(int jobId)
        {
            return this.ExecuteProxyContract<DataService.IDataService, JobResultsFileLocationInfo>(ds => ds.GetJobResultsFileLocation(jobId)).Just();
        }

        public Maybe<FileSetDataDistributionSummary> GetFileSetDataDistribution(int fileSetId)
        {
            return this.ExecuteProxyContract<DataService.IDataService, FileSetDataDistributionSummary>(ds => ds.GetFileSetDataDistribution(fileSetId)).Just();
        }
    }
}
